# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: xguo

from enum import Enum, _EnumDict
import sys

def gen_binance_enum_types(typename, value_list):
  if sys.version_info >= (3, 9, 2):
    return Enum(typename, dict(zip(value_list, range(len(value_list)))))
  enum_dict = _EnumDict()
  for value in value_list:
    enum_dict[value] = value
  cls = type(typename, (Enum,), enum_dict)
  return cls


BinanceSymbolStatus = gen_binance_enum_types("SymbolStatus",
                                             [
                                                 "PRE_TRADING",
                                                 "TRADING",
                                                 "POST_TRADING",
                                                 "END_OF_DAY",
                                                 "HALT",
                                                 "AUCTION_MATCH",
                                                 "BREAK",
                                             ])

BinanceOrderStatus = gen_binance_enum_types("OrderStatus",
                                            [
                                                "NEW",
                                                "PARTIALLY_FILLED",
                                                "FILLED",
                                                "CANCELED",
                                                "PENDING_CANCEL",
                                                "REJECTED",
                                                "EXPIRED",
                                            ])

BinanceExecutionType = gen_binance_enum_types(
    "ExecutionType",
    [
        "NEW",
        "CANCELED",
        "REPLACED",  # not used
        "REJECTED",
        "TRADE",
        "EXPIRED",
    ])

BinanceOrderType = gen_binance_enum_types("OrderTypes",
                                          [
                                              "LIMIT",
                                              "MARKET",
                                              "STOP_LOSS",
                                              "STOP_LOSS_LIMIT",
                                              "TAKE_PROFIT",
                                              "TAKE_PROFIT_LIMIT",
                                              "LIMIT_MAKER",
                                          ])

BinanceOrderSide = gen_binance_enum_types("OrderSide", [
    "BUY",
    "SELL",
])

BinanceTimeInForce = gen_binance_enum_types("TimeInForce", [
    "GTC",
    "IOC",
    "FOK",
])

BinanceNewOrderRespType = gen_binance_enum_types("NewOrderRespType", [
    "ACK",
    "RESULT",
    "FULL",
])
